import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
import { ApiService } from 'src/app/core/api';

@Injectable()
export class GuideDetailActivate implements Resolve<any> {
	constructor(private apiService: ApiService) {}
	resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
		console.log(route, state);
		const id = route.queryParams['travelGuideId'];
		const type = route.queryParams['type'];
		let url = '';
		const data: any = {};
		if (type == 1) {
			url = '导游详情';
			data['travelGuideId'] = id;
		} else {
			url = '导游产品详情';
			data['travelProductId'] = id;
		}
		return this.apiService
			.get(url, data)
			.then((e: any) => {
				return { del: e, guide: e['travelGuideForUserView'], pics: e['travelGuideForUserView']['images'].split(',') };
			})
			.catch(res => {
				return res;
			});
	}
}
